import requests
import time
import E_command

def inf():
    model_name = "Elysium_BD"
    model_function = "Elysium ERNIE-4.0-8K模型调用模块,本AI技术支持来自于百度官方,详细调试参数见设置后台"
    return model_name, model_function

# 百度ERNIE-4.0-8K模型参数
API_URL = "https://z2p2e3e0e0wdz6nf.aistudio-hub.baidu.com/chat/completions"
headers = {
    "Authorization": "5d58a8fb052335f6874c328223a0b7bd946c99cd",
    "Content-Type": "application/json"
}

def query(payload):
    try:
        response = requests.post(API_URL, headers=headers, json=payload)
        response.raise_for_status()  # 如果响应状态码不是200，引发HTTPError
        return response.json()
    except requests.RequestException as e:
        E_command.command_warn("服务器返回错误响应")
        return None

def print_with_animation(text):
    for char in text:
        print(char, end='', flush=True)
        time.sleep(0.05)  # 控制输出速度
    print()  # 换行

def Elysium_BD():
    E_command.command_elysium("欢迎使用Elysium智能助手！请输入你的问题或者对话内容，输入'exit'来退出对话。")
    while True:
        text = input("\nQ: ")
        if text.lower() == "exit":
            E_command.command_elysium("Elysium: 再见！欢迎下次再来！")
            break
        payload = {"messages": [{"role": "user", "content": text}]}
        output = query(payload)
        if output and "result" in output:
            response = output["result"]
            print("A:", end=' ')
            print_with_animation(response)
        else:
            E_command.command_warn("网络故障")
